toolHelp(){
    #工具根目录 
    toolBase=$1
    #工具名称
    toolName=${toolBase##*/}
    find "${toolBase}/roles" -name "Makefile-*" | while read line
    do 
       cmd_mod="${line##*-}"
       cmd_mod=${cmd_mod%%.*} 
       echo "${cmd_mod}"
       grep '^#-' ${line} | awk -F'#-' '{print "  "$2}'
       echo "  <=="
       #defHosts=$(grep "H=" ${line}  | wc | awk {'print $1'})
       #if [ "${defHosts}" = "1" ]; then
       #   export varHosts="localhost"
       #else
       #   export varHosts=
       #fi
       #${toolName}  ${cmd_mod}
       modHelp ${line} ${cmd_mod} ${toolBase##*/}
       echo ""
    done;
}
cmds(){
    #工具根目录 
    toolBase=$1
    #工具名称
    toolName=${toolBase##*/}
    echo ""
    echo "Support Modules:"
    echo ""
    toolHelp $1
    echo ""
    echo "Support Cmds:"
    echo ""
    cat "${toolBase}/Makefile" |  grep '^[^#[:space:]].*: ' | awk -F':' '{print $1" "$2}'
    echo ""

}
modHelp(){
    toolDir=$(dirname $1)
    playbookFile=${toolDir}/play-book.yaml
    grep '^[^#[:space:]].*: ' $1 | grep "#" | while read line2
    do
       cmdName="${line2%%:*}"
       cmdFull="${line2} #$3#$2#${cmdName}"
       result=$(echo $line2 | grep "\-L")
       #如果playbook存在且不是显示指定本地执行，则强制要求设置hosts
       if [ -f "${playbookFile}" -a -z "$result" ]; then
         echo ${cmdFull} |awk -F'#' {'printf "  %-10s %s \tusage: %s %s %s %s H=? //hosts\n", $1,$2,$4,$5,$6,$3'}
       else
         echo ${cmdFull} |awk -F'#' {'printf "  %-10s %s \tusage: %s %s %s %s\n", $1,$2,$4,$5,$6,$3'}
       fi
    done
    echo ""
}

newDir(){
    if [ ! -d $1 ]; then
       mkdir -p $1
    fi
    echo ""
}

setVars(){
    if [ $# -eq 2 ]; then
      echo -e "\n$1" | awk -F":" {'print $1": "$2'} >>$2
    else
      echo "must have e and file!"
    fi
}

case "$1" in
    'toolHelp')
        shift
        toolHelp $@
        ;;
    'newDir')
        shift
        newDir $@
        ;;
    'setVars')
        shift
        setVars $@
        ;;
    'modHelp')
        shift
        modHelp $@
        ;; 
    'cmds')
        shift
        cmds $@
        ;; 
    *)
    exit 1
        ;;
    esac
